Ext.define('appmod.view.knowledge.content.PostInfoForm', {
    extend: 'Ext.form.Panel',
    alias: [
		'widget.knowledge.content.postinfoform',
		'widget.knowledge-content-postinfoform'
	],
	requires: [
		'Ext.ux.TreePicker'
	],	
    bodyPadding: 10,
	
	constructor: function (config) {
		
		if (config.fieldStores) {
			this.fieldStores = config.fieldStores;
		}
        this.callParent(arguments);
     },	
	
    initComponent: function() {
      var me = this;

		var emptyStore = Ext.create('Ext.data.TreeStore',
		{
			root:
			{
				text: '信息分类',
				id: 'root',
				expanded: true,
				children:
				[
				]
			},
			folderSort: false
		});
		
		var dsCatelog = emptyStore;
		
		if (me.fieldStores != null) {
			if (me.fieldStores['dsCategory']) {
				dsCatelog = me.fieldStores['dsCategory'];
			}
		}
	  
      Ext.applyIf(me, {
	  	    fieldDefaults: {
            	labelWidth: 80
        	},
			autoScroll:true,
            items: [
                {
                    xtype: 'hiddenfield',
					name:'id',
                    anchor: '100%'
                },			
				{
                    xtype: 'textfield',
                    name: 'title',
                    fieldLabel: '主题',
					anchor: '50%',
					allowBlank:false
                },
                {
                    xtype: 'textfield',
                    name: 'keywords',
                    anchor: '50%',
					fieldLabel: '关键字'
                },
				{
                    xtype: 'htmleditor',
                    name: 'content',
                    anchor: '95%',
					height: 250,
					fieldLabel: '内容'
                },
                {
                    xtype: 'treepicker',
                    fieldLabel: '所属分类',
					store : dsCatelog,
					displayField:'text',
					name:'categoryId',
                    anchor: '50%'
                },				
				{
                    xtype: 'fieldcontainer',
					fieldLabel: '附件',
					width:600,
					items:[
						{
							xtype: 'tabpanel',
							activeTab: 0,
							plain: true,
							height:200,
					        defaults :{
					            autoScroll: true,
					            bodyPadding: 10
					        },
							items:[
								{
									title: '附件',
									items: [
										{
											xtype: 'filefield',
											buttonOnly: true,//仅显示按钮
				        					hideLabel: true,//隐藏标签
						                    buttonText: '添加附件',
											listeners: {
												'change': function(fb, v){
													me.fireEvent('addAttchment',{
														window : me,
														formPanel: me,
														fb:fb,
														v:v
													});	
												}
											}
										},
										{
											xtype:'grid',
											name:'attachmentGrid',
											columns:[
												{
								                    xtype: 'gridcolumn',
								                    dataIndex: 'name',
													flex:1,
								                    text: '附件名称'
								                },
								                {
								                    xtype: 'actioncolumn',
								                    dataIndex: 'coller',
								                    minWidth:130,
													text: '操 作',
													items:[
													{
														getClass: function(v, meta, rec) {          // Or return a class from a function
									                        this.items[0].tooltip = '删除该附件';
															return 'x-action-del'
									                    },
														handler: function(grid, rowIndex, colIndex){
															me.fireEvent('deleteAttchment',{
																grid : grid,
																rowIndex: rowIndex,
																colIndex:colIndex
															});																
														}
													}
													]

								                }
											]
											
										},
								
									
										
									]
								}
							]
						}
					]
                }			
            ]		
        });

        me.callParent(arguments);
    }

});